import logging
import re

from utils.yaml_tool import read_data_from_yaml
from conf.settings import VAR_DATA_PATH, PATTERN
import logging
logger = logging.getLogger(__name__)

def var_substitution(param):
    '''先获取常用变量，为后续替换为实际值提供数据'''

    # var_dic = read_data_from_yaml(VAR_DATA_PATH)
    # logger.info("常用变量：{}".format(var_dic))
    var_dic= cv.getCommonVar()
    logger.info("常用变量：{}".format(var_dic))

    for key in var_dic:
        if key in param:
            param = param.repkace(key,str(var_dic[key])) # replace 返回替换后的新的字符串
    return  param

def parameter_substitution(param):
    '''依赖参数值替换为实际值'''

    keys = re.findall(PATTERN,param)
    print(keys)
    for key in keys:
        value = gv.getVar(key)
        param = param.replace('${' + key + '}',str(value))   # replace 返回替换后的新字符串
    return param



